#include <stdio.h>
#include <stdlib.h>

double s1 = 0.0;
double s2 = 1.0;
double step = 0.01;
double func(), value(double (*)());

int main()
{
    printf("最小值是：%2.3f\n", value(func)); //使用函数参数调用
    system("pause");
    return 0;
}

double func(double x) //目标函数
{
    return (10 * x * x - 9 * x + 2);
}

// 定义求最小值函数，使用函数指针作为参数
double value(double (*f)())
{
    double x = s1, y = (*f)(x);
    while (x <= s2)
    {
        if (y > (*f)(x))
            y = (*f)(x);
        x += step;
    }
    return y;
}